refactor(airc-bash): extract cmd_teardown + cmd_disconnect#216
refactor(airc-bash): extract cmd_teardown + cmd_disconnect#216
Conversation
…file split Pulls the leave/cleanup verbs (cmd_teardown + cmd_disconnect, 253 lines) out of the airc top-level into lib/airc_bash/cmd_teardown.sh. airc: 3153 → 2909 lines (-244) lib/airc_bash/cmd_teardown.sh: +273 (253 body + 20 header) Both verbs share the kill loop and split on what to clear afterwards (teardown wipes more aggressively; disconnect preserves identity + peers + history). Logically one group. Verified bash -n + smoke dispatch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Extracts the teardown/disconnect “leave/cleanup” verbs from the airc bash monolith into a dedicated sourced module, continuing the ongoing Phase 0/3 modularization of airc into lib/airc_bash/* command files.
Changes:
- Adds
lib/airc_bash/cmd_teardown.shcontainingcmd_teardownandcmd_disconnect. - Removes the inline implementations from
aircand sources the new module via_airc_lib_dir.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
lib/airc_bash/cmd_teardown.sh |
New extracted module implementing cmd_teardown/cmd_disconnect. |
airc |
Replaces inline teardown/disconnect functions with a source of the new module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for lpid in $lpids; do | ||
| local cmd | ||
| cmd=$(proc_cmdline "$lpid" || true) | ||
| if echo "$cmd" | grep -q "socket.SOCK_STREAM\|socket.AF_INET"; then |
There was a problem hiding this comment.
grep -q "socket.SOCK_STREAM\|socket.AF_INET" relies on a non-POSIX alternation escape (and the unescaped .s are regex wildcards). This can fail on some greps (notably non-GNU) and may match unintended strings. Prefer a portable fixed-string match (e.g., grep -F with multiple -e patterns) or grep -E with properly escaped dots.
| if echo "$cmd" | grep -q "socket.SOCK_STREAM\|socket.AF_INET"; then | |
| if echo "$cmd" | grep -F -q -e 'socket.SOCK_STREAM' -e 'socket.AF_INET'; then |
| if [ -f "$CONFIG" ]; then | ||
| "$AIRC_PYTHON" -c " | ||
| import json | ||
| try: | ||
| c = json.load(open('$CONFIG')) | ||
| for k in ('host_target', 'host_name', 'host_airc_home', 'host_port', 'host_ssh_pub'): | ||
| c.pop(k, None) | ||
| json.dump(c, open('$CONFIG', 'w'), indent=2) | ||
| except Exception: | ||
| pass | ||
| " 2>/dev/null || true | ||
| fi |
There was a problem hiding this comment.
cmd_disconnect edits config via an inline python -c string that interpolates $CONFIG directly into the Python source. This is quoting-fragile (paths with ' break) and duplicates the repo’s existing config helper. Use unset_config_keys (already available in airc) to clear the host-pairing keys, and include host_identity in the cleared set to fully remove cached host pairing state.
| if [ -f "$CONFIG" ]; then | |
| "$AIRC_PYTHON" -c " | |
| import json | |
| try: | |
| c = json.load(open('$CONFIG')) | |
| for k in ('host_target', 'host_name', 'host_airc_home', 'host_port', 'host_ssh_pub'): | |
| c.pop(k, None) | |
| json.dump(c, open('$CONFIG', 'w'), indent=2) | |
| except Exception: | |
| pass | |
| " 2>/dev/null || true | |
| fi | |
| unset_config_keys \ | |
| host_target \ | |
| host_name \ | |
| host_airc_home \ | |
| host_port \ | |
| host_ssh_pub \ | |
| host_identity >/dev/null 2>&1 || true |
| # External cross-references (call-time): die, ensure_init, get_config_val, | ||
| # unset_config_keys, proc_airc_pids_matching, port_listeners, AIRC_HOME, |
There was a problem hiding this comment.
The header comment’s “External cross-references” list appears out of sync with the actual implementation (e.g., die/ensure_init/get_config_val/unset_config_keys aren’t called in cmd_teardown, while proc_children/proc_parent/proc_cmdline are). Updating this list will keep the module’s dependency documentation accurate.
| # External cross-references (call-time): die, ensure_init, get_config_val, | |
| # unset_config_keys, proc_airc_pids_matching, port_listeners, AIRC_HOME, | |
| # External cross-references (call-time): proc_airc_pids_matching, | |
| # proc_children, proc_parent, proc_cmdline, port_listeners, AIRC_HOME, |
Pulls the leave/cleanup verbs (cmd_teardown + cmd_disconnect, 253 lines) into lib/airc_bash/cmd_teardown.sh. airc: 3153 → 2909 (-244). Stacks alongside #213/#214/#215.